Skip to content

Conversation

ayushb
Copy link
Member

@ayushb ayushb commented Sep 16, 2026

Solves #10. Stacked on #26, so review that one first. Only the one commit here is new.

Fills the gaps left in the suite. Nothing in here touches the network.

What was untested

  • api/pokemon.ts had no tests at all, which is the one module that actually calls out
  • FavoritePokemon had no test file
  • GetNextFiltered and GetPrevFiltered were only exercised indirectly, through mocks in the list tests
  • PokemonCard had no test for the sprite state, so the bug where the card kept showing the previous pokemon's sprite could come back unnoticed
  • Nothing checked that the pieces work together, or that choices actually reach storage

What is added

api/pokemon.test.ts, five tests. fetch is stubbed, so the suite cannot reach pokeapi even by accident. Covers the url it builds, a failed response, and that an out of range id is rejected before any request goes out.

FavoritePokemon.test.tsx, seven tests plus a snapshot. Props, ordering by id regardless of the order the list arrives in, that the component does not sort the caller's array in place, the selected marker, the click handler, and the empty state.

PokemonCard.test.tsx, four more tests. Stepping through the four sprites, wrapping at the end, the base stat total, and a regression test for going back to the default sprite when a different pokemon is passed in.

pokemonController.test.ts, five more tests for the filtered navigation. That it walks past pokemon which do not match, that it walks backwards for prev, that it stops at the ends, and that one failed fetch does not stop the walk.

App.test.tsx, six tests. Loading, next and prev, prev disabled on the first pokemon, a favorite reaching local storage, a filter choice reaching session storage, and stored rules being restored on mount. This is the part that shows both storage apis in use from the user's side.

Checks

before here
vitest run 48 passed, 9 files 75 passed, 12 files
tsc -b clean clean
eslint . clean clean
prettier --check clean clean
vite build builds builds

Two things this does not cover

Cross browser and mobile testing. The issue asks for it, but it is manual work on whatever devices we have, not something a test file can do. It needs writing up in the readme, so it belongs with #14.

An off by one in the api guard. getPokemonByID rejects id < 0, but its own error message says 0 < id <= 1025. So id 0 passes validation and goes to pokeapi, which has no pokemon 0. I left the behaviour alone rather than changing the api inside a testing PR, and the tests do not assert either way on it. Worth its own small fix.

…tion

* Add api tests that stub fetch so nothing reaches the network
* Add FavoritePokemon tests for props, ordering, selection and the empty state
* Add PokemonCard tests for stepping through sprites and resetting on a new pokemon
* Add GetNextFiltered and GetPrevFiltered tests, including recovery from a failed fetch
* Add App tests that check navigation and that choices reach local and session storage
* Add snapshots for the favorites view

References #10
@ayushb ayushb requested a review from a team as a code owner September 16, 2026 08:47
Copy link
Member

@thomhet thomhet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ayushb ayushb merged commit 15d4220 into feat/mvp-filters-and-build-fixes Sep 16, 2026
@thomhet thomhet deleted the feat/issue-10-tests branch September 18, 2026 22:58
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants